#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>

#ifdef NON_OS

#else

#endif

#include <config.h>
#include <types.h>
#ifdef BMP_SUPPORT
#include <image_bmp.h>
#endif
#ifdef JPEG_SUPPORT
#include <image_jpeg.h>
#endif
#include <gobjs.h>
#include <image.h>
#include <misc.h>

extern char *screen_base;
extern u32 fbsize;

#ifdef BMP_SUPPORT
static BMP *bmp_obj;
#endif
#ifdef JPEG_SUPPORT
static JPEG *jpeg_obj;
#endif


int load_image(IMAGE *img, u8 *img_name)
{
#ifdef BMP_SUPPORT
    if((int)(bmp_obj = load_bmp(img_name)) > 0) {
        img->width = bmp_obj->biWidth;
        img->height = bmp_obj->biHeight;
        img->data = (u8 *)bmp_obj->data;
        free(bmp_obj);
        return 0;
    }
#endif
#ifdef JPEG_SUPPORT  
    if((int)(jpeg_obj = load_jpeg(img_name)) > 0) {
        img->width = jpeg_obj.width;
        img->height = jpeg_obj.height;
        img->data = (u8 *)jpeg_obj.data;
        free(jpeg_obj);
        return 0;
    }
#endif
    
    return -2; /* Not a supported image format */
}
